package com.cino.util;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
public class AjaxResult<T> {

    public static Boolean success = true;
    public static String msg = "操作成功";
    public static Integer code= 200;
    private T data;


    public AjaxResult(){

    }

    public AjaxResult(Boolean success, String msg,Integer code , T data) {
        this.success = success;
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public static <T> AjaxResult success(T data) {
       return new AjaxResult(true,"操作成功",200,data);
    }

    public static <T> AjaxResult failed(T data) {
        return new AjaxResult(false,"操作失败",500,data);
    }

    public static AjaxResult success(){
        return  new AjaxResult(true,"操作成功",200,null);
    }

    public static AjaxResult failed(String message){
        return  new AjaxResult(false,message,500,null);
    }


    public Boolean getSuccess() {
        return success;
    }

    public String getMsg() {
        return msg;
    }

    public Integer getCode() {
        return code;
    }

    public T getData() {
        return data;
    }

    //链式语法的改造
    public static AjaxResult me(){
        return new AjaxResult();
    }
    public AjaxResult setSuccess(Boolean success) {
        this.success = success;
        return this;
    }
    public AjaxResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }
    public AjaxResult setCode(Integer code) {
        this.code = code;
        return this;
    }
    public AjaxResult setObj(T data) {
        this.data = data;
        return this;
    }


}
